class Chat {
  int? id;
  int sendUserId;
  int acceptUserId;
  String context;
  DateTime sendTime;
  bool isRead;

  Chat({
    this.id,
    required this.sendUserId,
    required this.acceptUserId,
    required this.context,
    required this.sendTime,
    this.isRead = false,
  });

  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'sendUserId': sendUserId,
      'acceptUserId': acceptUserId,
      'context': context,
      'sendTime': sendTime.millisecondsSinceEpoch,
      'isRead': isRead ? 1 : 0,
    };
  }

  factory Chat.fromMap(Map<String, dynamic> map) {
    return Chat(
      id: map['id'],
      sendUserId: map['sendUserId'],
      acceptUserId: map['acceptUserId'],
      context: map['context'],
      sendTime: DateTime.fromMillisecondsSinceEpoch(map['sendTime']),
      isRead: (map['isRead'] ?? 0) == 1,
    );
  }

  Chat copyWith({
    int? id,
    int? sendUserId,
    int? acceptUserId,
    String? context,
    DateTime? sendTime,
    bool? isRead,
  }) {
    return Chat(
      id: id ?? this.id,
      sendUserId: sendUserId ?? this.sendUserId,
      acceptUserId: acceptUserId ?? this.acceptUserId,
      context: context ?? this.context,
      sendTime: sendTime ?? this.sendTime,
      isRead: isRead ?? this.isRead,
    );
  }
}
